package com.ruoyi.mall.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallOrderMasterMapper;
import com.ruoyi.mall.domain.MallOrderMaster;
import com.ruoyi.mall.service.IMallOrderMasterService;

/**
 * 订单管理Service业务层处理
 * 
 * @author banana_slices
 * @date 2024-12-01
 */
@Service
public class MallOrderMasterServiceImpl extends ServiceImpl<MallOrderMasterMapper, MallOrderMaster> implements IMallOrderMasterService
{
    @Autowired
    private MallOrderMasterMapper mallOrderMasterMapper;

    /**
     * 查询订单管理
     * 
     * @param orderId 订单管理主键
     * @return 订单管理
     */
    @Override
    public MallOrderMaster selectMallOrderMasterByOrderId(Long orderId)
    {
        return mallOrderMasterMapper.selectMallOrderMasterByOrderId(orderId);
    }

    /**
     * 查询订单管理列表
     * 
     * @param mallOrderMaster 订单管理
     * @return 订单管理
     */
    @Override
    public List<MallOrderMaster> selectMallOrderMasterList(MallOrderMaster mallOrderMaster)
    {
        return mallOrderMasterMapper.selectMallOrderMasterList(mallOrderMaster);
    }

    /**
     * 新增订单管理
     * 
     * @param mallOrderMaster 订单管理
     * @return 结果
     */
    @Override
    public int insertMallOrderMaster(MallOrderMaster mallOrderMaster)
    {
        mallOrderMaster.setCreateTime(DateUtils.getNowDate());
        return mallOrderMasterMapper.insertMallOrderMaster(mallOrderMaster);
    }

    /**
     * 修改订单管理
     * 
     * @param mallOrderMaster 订单管理
     * @return 结果
     */
    @Override
    public int updateMallOrderMaster(MallOrderMaster mallOrderMaster)
    {
        mallOrderMaster.setUpdateTime(DateUtils.getNowDate());
        return mallOrderMasterMapper.updateMallOrderMaster(mallOrderMaster);
    }

    /**
     * 批量删除订单管理
     * 
     * @param orderIds 需要删除的订单管理主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderMasterByOrderIds(Long[] orderIds)
    {
        return mallOrderMasterMapper.deleteMallOrderMasterByOrderIds(orderIds);
    }

    /**
     * 删除订单管理信息
     * 
     * @param orderId 订单管理主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderMasterByOrderId(Long orderId)
    {
        return mallOrderMasterMapper.deleteMallOrderMasterByOrderId(orderId);
    }

    @Override
    public Boolean checkOrderMasterExist(Long orderId) {
        if (orderId == null) return false;
        //设置查询条件
        LambdaQueryWrapper<MallOrderMaster> lqw = new LambdaQueryWrapper<>();
        lqw.eq(MallOrderMaster::getOrderId, orderId);
        lqw.eq(MallOrderMaster::getDelFlag, '0');
        //调用查询业务
        return mallOrderMasterMapper.selectOne(lqw) != null;
    }
}
